#include <stdio.h>
#include <string.h>

int main() {
	typedef struct {
		char name[13] = {0};
		int vcount;
		int score;
	} Team;
	int N;
	int i, j;
	Team result[10] = {{0}, 0, 0};
	scanf("%d", &N);
	int a[10][10] = {0};
	for (i = 0; i < N; i++) {
		scanf("%s", result[i].name);
	}
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			scanf("%d", &a[i][j]);
		}
	}

	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			if (a[i][j] > 0)
				result[i].vcount++;
			if (a[i][j] == 3 || a[i][j] == 4)
				result[i].score += 3;
			if (a[i][j] == 5)
				result[i].score += 2;
			if (a[i][j] == -5)
				result[i].score += 1;
		}
	}

	for (i = 0; i < N - 1; i++) {
		int flag = 0;
		for (j = 0; j < N - i - 1; j++) {
			if ((result[j].vcount < result[j + 1].vcount) || (result[j].vcount == result[j + 1].vcount
			        && result[j].score < result[j + 1].score) || (result[j].vcount == result[j + 1].vcount
			                && result[j].score == result[j + 1].score && strcmp(result[j].name, result[j + 1].name) > 0)) {
				Team t = result[j];
				result[j] = result[j + 1];
				result[j + 1] = t;
				flag = 1;
			}
		}
		if (flag == 0)
			break;
	}
	for (i = 0; i < N; i++) {
		printf("%s %d %d\n", result[i].name, result[i].vcount, result[i].score);
	}
	return 0;
}